package com.kaibes.platform.file.client.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import com.kaibes.core.base.util.AesUtils;
import com.kaibes.platform.file.client.db.FileServer;

@Component
public class FileServerUtils {

	@Autowired
    private RestTemplate restTemplate;
	
	public boolean test(FileServer testServer) {
		try {
			String hello = "hello world!";
			String ciphertext = AesUtils.CBC.encrypt2String64(hello, testServer.getAesKey(), testServer.getAesIv());
			String url = testServer.getHost()+"/encrypts/files/test/"+testServer.getUserId()+"/"+ciphertext;
			// 测试服务器是否可用
			restTemplate.getForObject(url, String.class);
			return true;
		}catch (Exception e) {
			return false;
		}
	}
	
}
